package com.eatme.web.core;

import com.eatme.core.array.Array;
import com.eatme.core.array.ArrayGenerator;
import com.eatme.core.search.LinearSearch;
import com.eatme.core.sort.SelectionSort;
import com.eatme.core.sort.SortingHelper;

public class Student implements Comparable<Student>{

    private String name;
    private  int score;

    public Student(String name) {
        this.name = name;
    }

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return  true;
        if (obj ==null)
            return  false;
        if (this.getClass()!=obj.getClass())
            return false;
        Student another = (Student) obj;
        return this.name.equals(another.name);
    }

    @Override
    public int compareTo(Student o) {
//        if (this.score< o.score)
//            return -1;
//        else  if(this.score==o.score)
//            return 0;
//        return 1;
        return this.score-o.score;
    }

    @Override
    public String toString() {
        return String.format("Student(name: %s, score: %d)",name,score);
    }


    public static void main(String[] args) {
        Array<Student> array = new Array<>();
        array.addLast(new Student("Alice",100));
        array.addLast(new Student("Bobo",66));
        array.addLast(new Student("Charles",88));
        System.out.println(array);

        int[] dataSize = {10000,100000};
        for (int n: dataSize) {
            Integer[] arr = ArrayGenerator.generateRandomArray(n,n);
            SortingHelper.sortTest("SelectionSort",arr);
        }
        Student[] students = {
                new Student("Alice",98),
                new Student("Bobo",99),
                new Student("Charles",52)
        };
        SelectionSort.sort(students);
        for (Student student: students)
            System.out.print(student+ " ");
        System.out.println();

        Student[] students2 = {new Student("Alice"),new Student("Bobo"),new Student("Charles")};
        Student bobo = new Student("Bobo");
        int res3 = LinearSearch.search(students2,bobo);
        System.out.println(res3);

    }
}
